﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using Common;
using System.Web.SessionState;
using System.Dynamic;
using Model;
using DAL;
using System.Data;
using System.Net;
using System.Text;
using JPushAPI;
using System.Security.Cryptography;

namespace UI.tools
{
    /// <summary>
    /// Admin 的摘要说明
    /// </summary>
    public class Admin : IHttpHandler, IRequiresSessionState
    {
        static Dictionary<string, Func<string>> hs = new Dictionary<string, Func<string>>();
        static DataTable dt = new DataTable();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = JobRequest.GetRequestString("act");
            string result = string.Empty;
            //if (Commons.CheckSign())
            //{
            result = hs[action]();
            //}
            //else
            //{
            //    result = Commons.GetFaild("身份验证失败");
            //}
            context.Response.Write(result);
            context.Response.End();
        }
        static Admin()
        {
            /*后台登陆*/
            #region 获取管理员列表
            hs.Add("Find_Admin", () =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string model = JobRequest.GetRequestString("model"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                //List<AdminInfo> list = AdminDAL.FindPage(keyword, begindate, enddate, page, limit, "", "", out count);
                List<AdminInfo> list = AdminDAL.FindPage(keyword, model, enddate, page, limit, "", "", out count);

                return Commons.GetPager("获取成功", list, count);
            });
            #endregion
            #region 保存管理员
            hs.Add("Save_Admin", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string username = JobRequest.GetRequestString("username"); //用户名
                string realname = JobRequest.GetRequestString("realname"); //真是姓名
                string userpwd = DESEncrypt.Encrypt(JobRequest.GetRequestString("userpwd")); //密码
                string power = JobRequest.GetRequestString("power"); //权限
                if (id > 0) {
                    if (power == "")
                    {
                        AdminInfo admininfo = AdminDAL.FindOneByID(id);
                        power = admininfo.Power;
                    }
                }                
                string founder = B.MyAdmin.RealName;//创建人
                int dataqx = JobRequest.GetRequestInt("dataqx");//查看原始数据权限
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                AdminInfo info = new AdminInfo()
                {
                    ID = id,
                    UserName = username,
                    UserPwd = userpwd,
                    RealName = realname,
                    Power = power,
                    Founder = founder, 
                    DataQX = dataqx,
                    CreateDate = DateTime.Now,
                };
                if (id == 0)
                {
                    ID = AdminDAL.Save(info);
                }
                else
                {
                    ID = AdminDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion
            #region 后台登陆
            hs.Add("Login", () =>
            {
                //参数
                try
                {
                    string username = JobRequest.GetRequestString("username"); //用户名
                    string userpwd = JobRequest.GetRequestString("userpwd"); //密码
                    bool rememberme = JobRequest.GetRequestBool("rememberme"); //是否记住密码
                    int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                    //参数
                    AdminInfo info = AdminDAL.Login(username, DESEncrypt.Encrypt(userpwd));
                    if (info.ID > 0)
                    {
                        if (source == 1 || source == 0)
                        {
                            B.MyAdmin = info;
                        }
                        if (rememberme)
                        {
                            CookieHelper.WriteCookie("admin_username", username, 43200);
                            CookieHelper.WriteCookie("admin_userpwd", userpwd, 43200);
                            CookieHelper.WriteCookie("admin_rememberme", "true", 43200);
                        }
                        else
                        {
                            CookieHelper.WriteCookie("admin_username", "", 43200);
                            CookieHelper.WriteCookie("admin_userpwd", "", 43200);
                            CookieHelper.WriteCookie("admin_rememberme", "false", 43200);
                        }
                        
                        return Commons.GetSuccess("登陆成功", info);
                    }
                    else
                    {
                        return Commons.GetFaild("用户名或密码错误");
                    }
                }
                catch (Exception ex)
                {
                    return Commons.GetFaild(ex.Message);
                }
            });
            #endregion
            #region 修改密码
            hs.Add("Update_Pwd", () =>
            {
                //参数
                int userid = JobRequest.GetRequestInt("userid"); //用户ID
                string oldpwd = JobRequest.GetRequestString("oldpwd"); //旧密码
                string newpwd = JobRequest.GetRequestString("newpwd"); //新密码
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                AdminInfo user = new AdminInfo();
                if (source == 1 || source == 0)
                {
                    user = B.MyAdmin;
                }
                else
                {
                    user = AdminDAL.FindOneByID(userid);
                }

                if (user.UserPwd != oldpwd)
                {
                    return Commons.GetFaild("旧密码错误");
                }
                bool ok = CommonDAL.UpdateColumnByID(user.ID, "userpwd", DESEncrypt.Encrypt(newpwd), "[admin]");
                if (ok)
                {
                    if (source == 1 || source == 0)
                    {
                        B.MyAdmin.UserPwd = newpwd;
                    }
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 删除管理员
            hs.Add("Delete_Admin", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 设置权限
            hs.Add("Power_Admin", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //用户ID
                string power = JobRequest.GetRequestString("power"); //权限，用户id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.UpdateColumnByID(id, "Power", power, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("设置成功", "");
                }
                else
                {
                    return Commons.GetFaild("设置失败");
                }
            });
            #endregion

            /*用户*/
            #region 获取用户列表
            hs.Add("Find_User", () =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<UserInfo> list = UserDAL.FindPage(keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetPager("获取成功", list, count);
            });
            #endregion           
            #region 保存用户
            hs.Add("Save_User", () =>
            {

                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string username = JobRequest.GetRequestString("username"); //用户名
                string userpwd = JobRequest.GetRequestString("userpwd"); //密码
                string realname = JobRequest.GetRequestString("realname"); //真实姓名
                string sex = JobRequest.GetRequestString("sex"); //性别
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                UserInfo info = new UserInfo()
                {
                    ID = id,
                    UserName=username,
                    UserPwd = DESEncrypt.Encrypt(userpwd),
                    RealName=realname,
                    Sex = sex,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = UserDAL.Save(info);
                }
                else
                {

                    ID = UserDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除用户
            hs.Add("Delete_User", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[user]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 导出用户
            hs.Add("Export_User", () =>
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("姓名");
                dt.Columns.Add("手机号");
                List<UserInfo> list = UserDAL.FindAll();
                foreach (UserInfo info in list)
                {
                    DataRow dr = dt.NewRow();
                    dr["姓名"] = info.RealName;
                    dr["手机号"] = info.Mobile;
                    dt.Rows.Add(dr);
                }
                Common.ExcelHelper.DataTableToExcel(dt, "用户手机号-" + DateTime.Now.ToString("yyyy-MM-dd"));
                return Commons.GetSuccess("导出成功", "");
            });
            #endregion


            /*客服*/
            #region 获取客服
            hs.Add("Find_Kf", () =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<KfInfo> list = KfDAL.FindPage(keyword, page, limit, "", "", out count);
                return Commons.GetPager("获取成功", list, count);
            });
            #endregion
            #region 保存客服
            hs.Add("Save_Kf", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string name = JobRequest.GetRequestString("name"); //客服姓名
                string mobile = JobRequest.GetRequestString("mobile"); //客服电话
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                KfInfo info = new KfInfo()
                {
                    ID = id,
                    Mobile = mobile,
                    Name = name
                };
                if (id == 0)
                {
                    ID = KfDAL.Save(info);
                }
                else
                {

                    ID = KfDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除客服
            hs.Add("Delete_Kf", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[kf]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*广告*/
            #region 获取广告
            hs.Add("Find_Ad", () =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<AdInfo> list = AdDAL.FindPage(keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetPager("获取成功", list, count);
            });
            #endregion
            #region 保存广告
            hs.Add("Save_Ad", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string name = JobRequest.GetRequestString("name"); //名称
                string img = JobRequest.GetRequestString("img").Replace(Commons.domain, ""); //图片
                string link = JobRequest.GetRequestString("link"); //链接
                int position = JobRequest.GetRequestInt("position"); //位置
                DateTime begindate = JobRequest.GetRequestDateTime("begindate", DataConvert.DefaultDateTimeValue);
                DateTime enddate = JobRequest.GetRequestDateTime("enddate", DataConvert.DefaultDateTimeValue);
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                AdInfo info = new AdInfo()
                {
                    ID = id,
                    Name = name,
                    Img = img,
                    Link = link,
                    Position = position,
                    BeginDate = begindate,
                    EndDate = enddate,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = AdDAL.Save(info);
                }
                else
                {

                    ID = AdDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除广告
            hs.Add("Delete_Ad", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[ad]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*菜单*/
            #region 获取菜单
            hs.Add("Find_Menu", () =>
            {
                //参数
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<MenuInfo> alllist = MenuDAL.FindAll();
                List<MenuInfo> parentlist = alllist.Where(x => x.ParentID == 0).ToList();
                List<MenuInfo> list = new List<MenuInfo>();
                foreach (MenuInfo menu in parentlist)
                {
                    list.Add(menu);
                    list.AddRange(alllist.Where(x => x.ParentID == menu.ID));
                }
                return Commons.GetPager("获取成功", list, list.Count);
            });
            #endregion
            #region 保存菜单
            hs.Add("Save_Menu", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                int parentid = JobRequest.GetRequestInt("parentid"); //父ID
                string name = JobRequest.GetRequestString("name"); //菜单名称
                string path = JobRequest.GetRequestString("path"); //菜单路径
                string btns = JobRequest.GetRequestString("btns"); //按钮
                int sort = JobRequest.GetRequestInt("sort"); //排序
                int isshow = JobRequest.GetRequestInt("isshow"); //是否显示
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                MenuInfo info = new MenuInfo()
                {
                    ID = id,
                    ParentID = parentid,
                    Name = name,
                    Path = path,
                    Btns = btns,
                    Sort = sort,
                    IsShow = isshow
                };
                if (id == 0)
                {
                    ID = MenuDAL.Save(info);
                }
                else
                {
                    ID = MenuDAL.Update(info);
                }
                if (ID > 0)
                {
                    BtnsDAL.List = BtnsDAL.FindAll();
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除菜单
            hs.Add("Delete_Menu", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[menu]");
                if (ok)
                {
                    BtnsDAL.List = BtnsDAL.FindAll();
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*按钮*/
            #region 获取按钮
            hs.Add("Find_Btns", () =>
            {
                //参数
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<BtnsInfo> list = BtnsDAL.FindAll();
                dynamic obj = new ExpandoObject();
                obj.list = list;
                obj.count = count;
                return Commons.GetSuccess("获取成功", obj);
            });
            #endregion
            #region 保存按钮
            hs.Add("Save_Btns", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string name = JobRequest.GetRequestString("name"); //按钮名称
                string method = JobRequest.GetRequestString("method"); //按钮方法
                int sort = JobRequest.GetRequestInt("sort"); //排序
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                BtnsInfo info = new BtnsInfo()
                {
                    ID = id,
                    Name = name,
                    Method = method,
                    Sort = sort
                };
                if (id == 0)
                {
                    ID = BtnsDAL.Save(info);
                }
                else
                {

                    ID = BtnsDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除按钮
            hs.Add("Delete_Btns", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[btns]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
                     
            /*仓位*/
            #region 获取仓位
            hs.Add("Find_Position", () =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string position = JobRequest.GetRequestString("position"); //搜索关键词

                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<PositionInfo> list = PositionDAL.FindPage(keyword, position, enddate, page, limit, "", "", out count);
                return Commons.GetPager("获取成功", list, count);
            });
            #endregion
            #region 保存仓位
            hs.Add("Save_Position", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //仓位主键
                string code = JobRequest.GetRequestString("code"); //仓位编码
                string remarks = JobRequest.GetRequestString("remarks");//备注
                string founder = B.MyAdmin.RealName; //创建人
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                PositionInfo info = new PositionInfo()
                {
                    ID = id,
                    Code = code,
                    Remarks = remarks,
                    Founder = founder,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = PositionDAL.Save(info);
                }
                else
                {
                    ID = PositionDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else if (ID == -1)
                {
                    return Commons.GetFaild("该仓位已存在");
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion
            #region 删除仓位
            hs.Add("Delete_Position", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[position]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 根据仓位名获取仓位
            hs.Add("Find_PositionByPcode", () =>
            {
                //参数             
                string pcode = JobRequest.GetRequestString("pcode"); //搜索关键词
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                PositionInfo list = PositionDAL.FindOneByCode(pcode);
                if (list.ID > 0)
                {
                    int ID = list.ID;
                    return Commons.GetSuccess("获取成功", ID);
                }
                else
                {
                    return Commons.GetFaild("获取失败");
                }
            });
            #endregion

            /*日志*/
            #region 获取日志
            hs.Add("Find_Journal", () =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<JournalInfo> list = JournalDAL.FindPage(keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetPager("获取成功", list, count);
            });
            #endregion
            #region 保存日志
            hs.Add("Save_Journal", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //日志主键
                string username = B.MyAdmin.UserName; //登录账号
                string ip = Commons.GetWebClientIP(); ; //IP地址
                string cname = Dns.GetHostName(); //电脑名
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                JournalInfo info = new JournalInfo()
                {
                    ID = id,
                    UserName = username,
                    IP = ip,
                    CName = cname,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = JournalDAL.Save(info);
                }
                else
                {
                    ID = JournalDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除日志
            hs.Add("Delete_Journal", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[journal]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*入库*/
            #region 获取入库
            hs.Add("Find_Ruku", () =>
            {
                //参数
                string ucode = JobRequest.GetRequestString("ucode");//条码
                string rawid = JobRequest.GetRequestString("rawid");
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                RukuInfo rukuinfo = RukuDAL.FindOneByUCodeAndNumber(ucode,rawid);
                if (rukuinfo.ID > 0)
                {
                    return Commons.GetSuccess("获取成功",rukuinfo);
                }
                else {
                    return Commons.GetFaild("获取失败");
                }
                
            });
            #endregion
            #region 保存入库
            hs.Add("Save_Ruku", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //入库主键
                string name = JobRequest.GetRequestString("name"); //用户姓名
                string ucode = JobRequest.GetRequestString("ucode"); //条码号
                int bpcount = JobRequest.GetRequestInt("bpcount"); //玻片数量
                int lkcount = JobRequest.GetRequestInt("lkcount"); //蜡块数量
                int pid = JobRequest.GetRequestInt("pid"); //仓位ID
                string remarks = JobRequest.GetRequestString("remarks"); //备注
                string imgs = JobRequest.GetRequestString("imgs"); //图片
                int rawid = JobRequest.GetRequestInt("rawid");//原始数据id
                //DateTime createdate = JobRequest.GetRequestDateTime("createdate", DataConvert.DefaultDateTimeValue); //创建时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                RukuInfo info = new RukuInfo()
                {
                    ID = id,
                    Name = name,
                    UCode = ucode,
                    AName = B.MyAdmin.RealName,
                    BPCount = bpcount,
                    LKCount = lkcount,
                    PID = pid,
                    Remarks = remarks,
                    NumBer = rawid,
                    Imgs = imgs,
                   
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = RukuDAL.Save(info);
                }
                else
                {
                    ID = RukuDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("入库成功", ID);
                }
                else
                {
                    return Commons.GetFaild("入库失败");
                }
            });
            #endregion
            #region 删除入库
            hs.Add("Delete_Ruku", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[ruku]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 删除入库图片
            hs.Add("Delete_Ruku_Imgs", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //删除的id
                string imgs = JobRequest.GetRequestString("imgs");//删除的图片
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = RukuDAL.DeleteImgsByID(imgs,id);
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            #region 批量入库
            hs.Add("Save_RuKuByIDS", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids");//批量插入的ID集合
                int pid = JobRequest.GetRequestInt("pid"); //仓位ID
                string imgs = JobRequest.GetRequestString("imgs"); //图片                
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                ids = ids.Remove(ids.Length - 1);

                string[] arrayids = ids.Split(',');
                List<RukuInfo> rukulist = new List<RukuInfo>();
                foreach (string id in arrayids) {
                    int rid = DataConvert.ToInt(id);
                    RawdataInfo rinfo = RawdataDAL.FindOneByID(rid);
                    RukuInfo rukuinfo = new RukuInfo();
                    rukuinfo.ID = rinfo.ID;
                    rukuinfo.Name = rinfo.Name;
                    rukuinfo.UCode = rinfo.UCode;
                    rukuinfo.AName = B.MyAdmin.RealName;
                    rukuinfo.BPCount = rinfo.BPCount;
                    rukuinfo.LKCount = rinfo.LKCount;
                    rukuinfo.PID = pid;
                    rukuinfo.Remarks = "";
                    rukuinfo.NumBer = rinfo.ID;
                    rukuinfo.Imgs = imgs;
                    rukuinfo.CreateDate = DateTime.Now;

                    rukulist.Add(rukuinfo);
                }
                int rukucount = rukulist.Count();
                int returncouns = 0;
                for (int i = 0; i < rukulist.Count; i++) {
                    RukuInfo info = rukulist[i];

                    RukuDAL.SaveInfo(info);
                    returncouns = returncouns + 1;
                }
                if (rukucount == returncouns)
                {
                    return Commons.GetSuccess("入库成功", rukucount);
                }
                else
                {
                    return Commons.GetFaild("入库失败");
                }
            });
            #endregion

            /*还片*/
            #region 获取还片
            hs.Add("Find_Huanpian", () =>
            {
                //参数
                string ucode = JobRequest.GetRequestString("ucode");//条码
                int rawid = JobRequest.GetRequestInt("rawid");//原始数据id
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<HuanpianInfo> list = HuanpianDAL.FindListByUCode(ucode, rawid);
                return Commons.GetSuccess("获取成功", list);
            });
            #endregion
            #region 保存还片
            hs.Add("Save_Huanpian", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //还片主键
                string hpname = JobRequest.GetRequestString("hpname"); //还片人
                string ucode = JobRequest.GetRequestString("ucode"); //条码号
                int bpcount = JobRequest.GetRequestInt("bpcount"); //玻片数量
                int lkcount = JobRequest.GetRequestInt("lkcount"); //还片数量
                int pid = JobRequest.GetRequestInt("pid"); //仓位ID
                DateTime hpdate = JobRequest.GetRequestDateTime("hpdate", DataConvert.DefaultDateTimeValue); //还片日期
                string remarks = JobRequest.GetRequestString("remarks"); //备注
                string mobile = JobRequest.GetRequestString("mobile");//电话
                string imgs = JobRequest.GetRequestString("imgs"); //图片
                DateTime createdate = DateTime.Now; //创建时间
                int rawid = JobRequest.GetRequestInt("rawid");//原始数据id
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                HuanpianInfo info = new HuanpianInfo()
                {
                    ID = id,
                    HPName = hpname,
                    UCode = ucode,
                    AName = B.MyAdmin.RealName,
                    BPCount = bpcount,
                    LKCount = lkcount,
                    PID = pid,
                    HPDate = hpdate,
                    Remarks = remarks,
                    Mobile = mobile,
                    Imgs = imgs,
                    NumBer = rawid,
                    CreateDate = createdate
                };
                if (id == 0)
                {
                    ID = HuanpianDAL.Save(info);
                }
                else
                {
                    ID = HuanpianDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除还片
            hs.Add("Delete_Huanpian", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[huanpian]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 删除还片图片
            hs.Add("Delete_Huanpian_Imgs", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //删除的id
                string imgs = JobRequest.GetRequestString("imgs");//删除的图片
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = HuanpianDAL.DeleteImgsByID(imgs,id);
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
                        
            #region 获取借片与还片
            hs.Add("Find_JPAndHP", () =>
            {
                //参数
                string ucode = JobRequest.GetRequestString("ucode");//条码
                int rawid = JobRequest.GetRequestInt("rawid");//原始数据id
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<HuanpianInfo> hplist = HuanpianDAL.FindListByUCode(ucode, rawid);
                List<JiepianInfo> jplist = JiepianDAL.FindListByUCode(ucode, rawid);

                dynamic obj = new ExpandoObject();
                obj.hplist = hplist;
                obj.jplist = jplist;
                return Commons.GetSuccess("获取成功", obj);
            });
            #endregion

            /*借片*/
            #region 获取借片
            hs.Add("Find_Jiepian", () =>
            {
                ////参数
                //string ucode = JobRequest.GetRequestString("ucode");//条码
                //int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                ////参数
                //int count = 0;
                //JiepianInfo info = JiepianDAL.FindOneByUCode(ucode);
                //if (info.ID > 0)
                //{
                //    return Commons.GetSuccess("获取成功", info);
                //}
                //else
                //{
                //    return Commons.GetFaild("获取失败");
                //}

                //参数
                string ucode = JobRequest.GetRequestString("ucode");//条码
                int rawid = JobRequest.GetRequestInt("rawid");//原始数据id
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<JiepianInfo> list = JiepianDAL.FindListByUCode(ucode,rawid);
                return Commons.GetSuccess("获取成功", list);
            });
            #endregion
            #region 保存借片
            hs.Add("Save_Jiepian", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //借片主键
                string jpname = JobRequest.GetRequestString("jpname"); //借片人
                string ucode = JobRequest.GetRequestString("ucode"); //条码号
                int bpcount = JobRequest.GetRequestInt("bpcount"); //玻片数量
                int lkcount = JobRequest.GetRequestInt("lkcount"); //蜡块数量
                int pid = JobRequest.GetRequestInt("pid"); //仓位ID
                DateTime jpdate = JobRequest.GetRequestDateTime("jpdate", DataConvert.DefaultDateTimeValue); //借片日期
                string remarks = JobRequest.GetRequestString("remarks"); //备注
                string mobile = JobRequest.GetRequestString("mobile");//电话
                string imgs = JobRequest.GetRequestString("imgs"); //图片                
                int rawid = JobRequest.GetRequestInt("rawid");//原始数据id
                DateTime createdate = DateTime.Now; //创建时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                JiepianInfo info = new JiepianInfo()
                {
                    ID = id,
                    JPName = jpname,
                    UCode = ucode,
                    AName = B.MyAdmin.RealName,
                    BPCount = bpcount,
                    LKCount = lkcount,
                    PID = pid,
                    JPDate = jpdate,
                    Remarks = remarks,
                    Mobile = mobile,
                    Imgs = imgs,
                    NumBer = rawid,
                    CreateDate = createdate
                };
                if (id == 0)
                {
                    ID = JiepianDAL.Save(info);
                }
                else
                {
                    ID = JiepianDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除借片
            hs.Add("Delete_Jiepian", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[jiepian]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 删除借片图片
            hs.Add("Delete_Jiepian_Imgs", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //删除的id
                string imgs = JobRequest.GetRequestString("imgs");//删除的图片
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = JiepianDAL.DeleteImgsByID(imgs, id);
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*原始数据*/
            #region 获取原始数据
            hs.Add("Find_Rawdata", () =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string hospital = JobRequest.GetRequestString("hospital"); //医院
                string experimentnumber = JobRequest.GetRequestString("experimentnumber"); //实验号
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                string ucode = JobRequest.GetRequestString("ucode"); //条码号
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<RawdataInfo> list = RawdataDAL.FindPage(keyword,ucode,hospital,experimentnumber,begindate, enddate, page, limit, "", "", out count);
                
                return Commons.GetPager("获取成功", list, count);
            });
            #endregion
            #region 保存原始数据
            hs.Add("Save_Rawdata", () =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //原始数据主键
                string name = JobRequest.GetRequestString("name"); //姓名
                string ucode = JobRequest.GetRequestString("ucode"); //条码号
                string blcode = JobRequest.GetRequestString("blcode"); //病理号
                int bpcount = JobRequest.GetRequestInt("bpcount"); //玻片数量
                int lkcount = JobRequest.GetRequestInt("lkcount"); //蜡块数量
                string hospital = JobRequest.GetRequestString("hospital"); //医院
                string remarks = JobRequest.GetRequestString("remarks"); //备注
                string founder = B.MyAdmin.RealName; //操作人
                string experimentnumber = JobRequest.GetRequestString("experimentnumber"); //实验号
                int sex = JobRequest.GetRequestInt("sex"); //性别
                int age = JobRequest.GetRequestInt("age"); //年龄
                string opinions = JobRequest.GetRequestString("opinions"); //诊断意见
                string reportdoctor = JobRequest.GetRequestString("reportdoctor"); //报告医生
                int tuwenshu = JobRequest.GetRequestInt("tuwenshu"); //图文数
                int datuwenshu = JobRequest.GetRequestInt("datuwenshu"); //大图文数
                string entryname = JobRequest.GetRequestString("entryname"); //项目名称
                string process = JobRequest.GetRequestString("process"); //病理流程
                string state = JobRequest.GetRequestString("state"); //状态
                string late = JobRequest.GetRequestString("late"); //迟
                string delayedcause = JobRequest.GetRequestString("delayedcause"); //迟发原因
                string outsourcingparty = JobRequest.GetRequestString("outsourcingparty"); //外包方
                string termination = JobRequest.GetRequestString("termination"); //终止
                string terminationreason = JobRequest.GetRequestString("terminationreason"); //终止原因
                string back = JobRequest.GetRequestString("back"); //退单
                string backreason = JobRequest.GetRequestString("backreason"); //退单原因
                string submitter = JobRequest.GetRequestString("submitter"); //提交人
                string auditor = JobRequest.GetRequestString("auditor"); //审核人
                string referencedoctor = JobRequest.GetRequestString("referencedoctor"); //取材医生
                DateTime specimensigningtime = JobRequest.GetRequestDateTime("specimensigningtime", DataConvert.DefaultDateTimeValue); //标本签收时间
                DateTime createdate = JobRequest.GetRequestDateTime("createdate", DataConvert.DefaultDateTimeValue); //创建时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                RawdataInfo info = new RawdataInfo()
                {
                    ID = id,
                    Name = name,
                    UCode = ucode,
                    BLCode = blcode,
                    BPCount = bpcount,
                    LKCount = lkcount,
                    Hospital = hospital,
                    Remarks = remarks,
                    Founder = founder,
                    ExperimentNumber = experimentnumber,
                    Sex = sex,
                    Age = age,
                    Opinions = opinions,
                    ReportDoctor = reportdoctor,
                    TuWenShu = tuwenshu,
                    DaTuWenShu = datuwenshu,
                    EntryName = entryname,
                    Process = process,
                    State = state,
                    Late = late,
                    DelayedCause = delayedcause,
                    OutsourcingParty = outsourcingparty,
                    Termination = termination,
                    TerminationReason = terminationreason,
                    Back = back,
                    BackReason = backreason,
                    Submitter = submitter,
                    Auditor = auditor,
                    ReferenceDoctor = referencedoctor,
                    SpecimenSigningTime = specimensigningtime,
                    CreateDate = createdate
                };
                if (id == 0)
                {
                    info.CreateDate = DateTime.Now;
                    ID = RawdataDAL.Save(info);
                }
                else
                {
                    ID = RawdataDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else if( ID == -1 )
                {
                    return Commons.GetFaild("该条码号已存在，保存失败");
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion
            #region 删除原始数据
            hs.Add("Delete_Rawdata", () =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[rawdata]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 根据条码获取原始数据
            hs.Add("Find_RawdataByucode", () =>
            {
                //参数
                string ucode = JobRequest.GetRequestString("ucode"); //结束时间
                string name = JobRequest.GetRequestString("name");//姓名
                string blcode = JobRequest.GetRequestString("blcode");//病理号
                string hospital = JobRequest.GetRequestString("hospital");//医院
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                RawdataInfo info = RawdataDAL.FindByUserInfo(ucode, name, blcode, hospital);
                if (info.ID > 0)
                {
                    return Commons.GetSuccess("获取成功", info);
                }
                else
                {
                    return Commons.GetFaild("没有获取到该条码信息");
                }
            });
            #endregion
            #region 修改打印信息
            hs.Add("update_rawdata_prints", () =>
            {
                //参数
                int ids = JobRequest.GetRequestInt("id"); //id
                string prints = JobRequest.GetRequestString("prints");
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ok = RawdataDAL.UpdatePrints(ids, prints);
          
                if (ok>0)
                {
                    return Commons.GetSuccess("", ok);
                }
                else
                {
                    return Commons.GetFaild("");
                }
            });
            #endregion

            /*入库数据*/
            #region 获取入库数据
            hs.Add("Find_RuKudata", () =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string hospital = JobRequest.GetRequestString("hospital"); //医院
                string experimentnumber = JobRequest.GetRequestString("experimentnumber"); //实验号
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                string ucode = JobRequest.GetRequestString("ucode"); //条码号
                int datatype = JobRequest.GetRequestInt("datatype");//数据类型
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<RawdataInfo> list = RawdataDAL.FindPageByRuKu(keyword, ucode, hospital, experimentnumber, begindate, enddate,datatype, page, limit, "", "", out count);
                
                return Commons.GetPager("获取成功", list, count);
            });
            #endregion

            #region 导入病理数据
            hs.Add("Import_Mobile1", () =>
            {

                //参数
                int pageindex = JobRequest.GetRequestInt("pageindex"); // id（非必填）
                int adminid = JobRequest.GetRequestInt("adminid");
                int a = 0;
                string ext = JobRequest.GetRequestString("ext");
                //参数
                dynamic obj = new ExpandoObject();
                try
                {
                    int count = 0;
                    if (pageindex == 1)
                    {
                        dt.Clear();
                    }
                    if (dt.Rows.Count == 0)
                    {
                        if (ext == "csv")
                        {
                            dt = Commons.CsvToDataTable(HttpContext.Current.Server.MapPath("/upload/excel/"), "mobile");
                        }
                        else
                        {
                            dt = Commons.ExcelToDataTable(HttpContext.Current.Server.MapPath("/upload/excel/mobile"+adminid+"." + ext), "");
                        }
                    }

                    count = dt.Rows.Count;
                    int pagesize = (count - 1) / 1000 + 1;
                    List<RawdataInfo> rawdatalist = new List<RawdataInfo>();

                    for (int i = (pageindex - 1) * 1000; i < pageindex * 1000 && i < count; i++)
                    {
                        try
                        {
                            DataRow row = dt.Rows[i];
                            //string name = row["Name"] + "";
                            //string ucode = row["UCode"] + "";
                            //string blcode = row["BLCode"] + "";
                            //int bpcount = DataConvert.ToInt(row["BPCount"]);
                            //int lkcount = DataConvert.ToInt(row["LKCount"]);
                            //string hospital = row["Hospital"]+"";
                            //string founder = row["Founder"] + "";
                            //string remarks = row["Remarks"] + "";
                            //string createdata = row["CreateDate"] + "";
                            string experimentnumber = row["实验号"]+"";
                            string ucode = row["主条码"]+"";
                            string name = row["姓名"] + "";
                            string sex = row["性别"]+"";
                            int sexs = 0;
                            if(sex == "女"){
                                sexs=1;
                            }

                            int age = DataConvert.ToInt(row["年龄"]);
                            string opinions = row["诊断意见"]+"";

                            string reportdoctor = row["报告医生"]+"";
                            int tuwenshu = DataConvert.ToInt(row["图文数"]);                           
                            int datuwenshu = DataConvert.ToInt(row["大体图文数"]);
                            int lkcount = DataConvert.ToInt(row["蜡块数量"]);
                            int bpcount = DataConvert.ToInt(row["玻片数量"]);
                            string hospital = row["医院"] + "";
                            string entryname = row["项目名称"]+"";
                            string process = row["病理流程"]+"";
                            string state = row["状态"]+"";
                            string late = row["迟"]+"";
                            string delayedcause = row["迟发原因"]+"";
                            string outsourcingparty = row["外包方"]+"";
                            string termination = row["终止"]+"";
                            string terminationreason = row["终止原因"]+"";
                            string back = row["退单"]+"";
                            string backreason = row["退单原因"]+"";
                            string submitter = row["提交人"]+"";
                            string auditor = row["审核人"]+"";
                            string referencedoctor = row["取材医生"]+"";
                            DateTime specimensigningtime =DataConvert.ToDateTime(row["标本签收时间"]);

                            //string blcode = row["病理号"] + "";
                            //string founder = row["操作人"] + "";
                            //string remarks = row["备注"] + "";
                            //string createdata = row["时间"] + "";                           

                            RawdataInfo info = new RawdataInfo() { 
                                Name = name,
                                UCode = ucode,
                                //BLCode = blcode,先将病理号，备注 设置为空
                                BLCode = experimentnumber,
                                BPCount = bpcount,
                                LKCount = lkcount,
                                Hospital = hospital,
                                Founder = B.MyAdmin.RealName,
                                //Remarks = remarks,
                                Remarks = "",

                                ExperimentNumber = experimentnumber,
                                Sex = sexs,
                                Age = age,
                                Opinions = opinions, 
                                ReportDoctor = reportdoctor,
                                TuWenShu = tuwenshu,
                                DaTuWenShu = datuwenshu,
                                EntryName = entryname,
                                Process = process,
                                State = state,
                                Late = late,
                                DelayedCause = delayedcause,
                                OutsourcingParty = outsourcingparty,
                                Termination = termination,
                                TerminationReason = terminationreason,
                                Back = back, 
                                BackReason = backreason,
                                Submitter = submitter,
                                Auditor = auditor,
                                ReferenceDoctor = referencedoctor,
                                SpecimenSigningTime = specimensigningtime,
                                DataType = 1,
                                CreateDate = DateTime.Now
                                
                            };
                            rawdatalist.Add(info);
                                 
                        }
                        catch (Exception ex)
                        {
                            Commons.Log(ex.Message);
                            return Commons.GetFaild("导入失败");
                        }
                    }
                    rawdatalist.Reverse();
                    for (int i = 0; i < rawdatalist.Count; i++) {
                        
                        int num = 0;
                        if (rawdatalist[i].Name != "" && rawdatalist[i].ExperimentNumber != "" && rawdatalist[i].Hospital != "")
                        {
                            num++;
                        }
                        if (rawdatalist[i].UCode != "" && rawdatalist[i].UCode != null)
                        {
                            num++;
                            //continue;
                        }
                        if (num >= 1)
                        {
                            RawdataDAL.Save(rawdatalist[i]);
                        }
                        else
                        {
                            continue;
                        }                
                    }

                        if (pageindex == pagesize)
                        {
                            pageindex = 0;
                            dt.Clear();
                        }
                        else
                        {
                            pageindex++;
                        }
                    obj.pagesize = pagesize;
                    obj.pageindex = pageindex;
                }
                catch (Exception ex)
                {
                    Commons.Log(ex.Message);
                    return Commons.GetFaild("导入失败");
                }
                return Commons.GetSuccess("导入成功", obj);
                
            });
            #endregion
            #region 导入血液数据
            hs.Add("Import_Mobile2", () =>
            {

                //参数
                int pageindex = JobRequest.GetRequestInt("pageindex"); // id（非必填）
                int adminid = JobRequest.GetRequestInt("adminid");
                int a = 0;
                string ext = JobRequest.GetRequestString("ext");
                //参数
                dynamic obj = new ExpandoObject();
                try
                {
                    int count = 0;
                    if (pageindex == 1)
                    {
                        dt.Clear();
                    }
                    if (dt.Rows.Count == 0)
                    {
                        if (ext == "csv")
                        {
                            dt = Commons.CsvToDataTable(HttpContext.Current.Server.MapPath("/upload/excel/"), "mobile");
                        }
                        else
                        {
                            //dt = Commons.ExcelToDataTable(HttpContext.Current.Server.MapPath("/upload/excel/mobiles"+adminid+"." + ext), "");
                            dt = Commons.ExcelToDataTable(HttpContext.Current.Server.MapPath("/upload/excel/mobiles" + adminid + ".xlsx"), "");
                        }
                    }

                    count = dt.Rows.Count;
                    int pagesize = (count - 1) / 1000 + 1;
                    List<RawdataInfo> rawdatalist = new List<RawdataInfo>();

                    for (int i = (pageindex - 1) * 1000; i < pageindex * 1000 && i < count; i++)
                    {
                        try
                        {
                            DataRow row = dt.Rows[i];
                            string ucode = row["主条码"] + "";
                            string experimentnumber = row["实验号"] + "";
                            int bpcount = DataConvert.ToInt(row["玻片数量"]);
                            string xuqiu = row["特殊需求"] + "";
                            string hospital = row["医院简称"] + "";
                            string name = row["病人姓名"] + "";
                            string sex = row["性别"] + "";
                            int sexs = 0;
                            if (sex == "女")
                            {
                                sexs = 1;
                            }
                            int age = DataConvert.ToInt(row["年龄"]);
                            string danwei = row["年龄单位"] + "";
                            DateTime specimensigningtime = DataConvert.ToDateTime(row["接收时间"]);
                            DateTime createdate = DataConvert.ToDateTime(row["录入时间"]);
                            
                            RawdataInfo info = new RawdataInfo()
                            {
                                Name = name,
                                UCode = ucode,
                                //BLCode = blcode,先将病理号，备注 设置为空
                                BLCode = experimentnumber,
                                BPCount = bpcount,
                                Hospital = hospital,
                                Founder = B.MyAdmin.RealName,
                                //Remarks = remarks,
                                Remarks = "",
                                Opinions="",
                                ReferenceDoctor="",
                                EntryName="",
                                Process = "",
                                State ="",

                                Late = "",
                                DelayedCause = "",
                                OutsourcingParty = "",
                                Termination = "",
                                TerminationReason = "",
                                Back = "",
                                BackReason = "",
                                Submitter = "",
                                Auditor = "",
                                ReportDoctor ="",
                                ExperimentNumber = experimentnumber,
                                Sex = sexs,
                                Age = age,
                                SpecimenSigningTime = specimensigningtime,
                                DataType = 2,
                                CreateDate = createdate
                            };
                            rawdatalist.Add(info);

                        }
                        catch (Exception ex)
                        {
                            Commons.Log(ex.Message);
                            return Commons.GetFaild("导入失败");
                        }
                    }
                    rawdatalist.Reverse();
                    for (int i = 0; i < rawdatalist.Count; i++)
                    {

                        int num = 0;
                        if (rawdatalist[i].Name != "" && rawdatalist[i].ExperimentNumber != "" && rawdatalist[i].Hospital != "")
                        {
                            num++;
                        }
                        if (rawdatalist[i].UCode != "" && rawdatalist[i].UCode != null)
                        {
                            num++;
                            //continue;
                        }
                        if (num >= 1)
                        {
                            RawdataDAL.Save(rawdatalist[i]);
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (pageindex == pagesize)
                    {
                        pageindex = 0;
                        dt.Clear();
                    }
                    else
                    {
                        pageindex++;
                    }
                    obj.pagesize = pagesize;
                    obj.pageindex = pageindex;
                }
                catch (Exception ex)
                {
                    Commons.Log(ex.Message);
                    return Commons.GetFaild("导入失败");
                }
                return Commons.GetSuccess("导入成功", obj);

            });
            #endregion

            /*修改配置信息*/
            #region 修改配置信息
            hs.Add("Update_Config", () =>
            {
                //参数
                string logo = JobRequest.GetRequestString("logo"); //logo
                string title = JobRequest.GetRequestString("title"); //网站标题
                string webname = JobRequest.GetRequestString("webname"); //系统名称
                string keyword = JobRequest.GetRequestString("keyword"); //网站关键词
                string description = JobRequest.GetRequestString("description"); //网站描述
                //参数
                ConfigInfo info = new ConfigInfo()
                {
                    ID = 1,
                    Logo = logo,
                    WebName = webname,
                    Title = title,
                    Keyword=keyword,
                    Description=description
                };
                int ID = ConfigDAL.Edit(info);
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", "");
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}